
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 07/08/2013 14:31:35
-- Generated from EDMX file: D:\Documents\Projects\Opentao.NotificationService\Common\Opentao.NotificationService.Common.Data\Entities\NSDbModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [D:\DOCUMENTS\PROJECTS\OPENTAO.NOTIFICATIONSERVICE\APPLICATION\OPENTAO.NOTIFICATIONSERVICE.APPLICATION.SERVICE\APP_DATA\NSDB.MDF];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_RecipientEventType_Recipient]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RecipientEventType] DROP CONSTRAINT [FK_RecipientEventType_Recipient];
GO
IF OBJECT_ID(N'[dbo].[FK_RecipientEventType_EventType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RecipientEventType] DROP CONSTRAINT [FK_RecipientEventType_EventType];
GO
IF OBJECT_ID(N'[dbo].[FK_Recipient_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_Recipient] DROP CONSTRAINT [FK_Recipient_inherits_EntityBase];
GO
IF OBJECT_ID(N'[dbo].[FK_EventType_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_EventType] DROP CONSTRAINT [FK_EventType_inherits_EntityBase];
GO
IF OBJECT_ID(N'[dbo].[FK_ImportanceLevel_inherits_EntityBase]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EntityBaseSet_ImportanceLevel] DROP CONSTRAINT [FK_ImportanceLevel_inherits_EntityBase];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[EntityBaseSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_Recipient]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_Recipient];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_EventType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_EventType];
GO
IF OBJECT_ID(N'[dbo].[EntityBaseSet_ImportanceLevel]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EntityBaseSet_ImportanceLevel];
GO
IF OBJECT_ID(N'[dbo].[RecipientEventType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RecipientEventType];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'EntityBaseSet'
CREATE TABLE [dbo].[EntityBaseSet] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'EntityBaseSet_Recipient'
CREATE TABLE [dbo].[EntityBaseSet_Recipient] (
    [Email] nvarchar(max)  NULL,
    [Phone] nvarchar(max)  NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_EventType'
CREATE TABLE [dbo].[EntityBaseSet_EventType] (
    [Title] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'EntityBaseSet_ImportanceLevel'
CREATE TABLE [dbo].[EntityBaseSet_ImportanceLevel] (
    [Title] nvarchar(max)  NOT NULL,
    [UseEmail] bit  NOT NULL,
    [UsePhone] bit  NOT NULL,
    [Id] int  NOT NULL
);
GO

-- Creating table 'RecipientEventType'
CREATE TABLE [dbo].[RecipientEventType] (
    [Subscribers_Id] int  NOT NULL,
    [Subscriptions_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'EntityBaseSet'
ALTER TABLE [dbo].[EntityBaseSet]
ADD CONSTRAINT [PK_EntityBaseSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_Recipient'
ALTER TABLE [dbo].[EntityBaseSet_Recipient]
ADD CONSTRAINT [PK_EntityBaseSet_Recipient]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_EventType'
ALTER TABLE [dbo].[EntityBaseSet_EventType]
ADD CONSTRAINT [PK_EntityBaseSet_EventType]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EntityBaseSet_ImportanceLevel'
ALTER TABLE [dbo].[EntityBaseSet_ImportanceLevel]
ADD CONSTRAINT [PK_EntityBaseSet_ImportanceLevel]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Subscribers_Id], [Subscriptions_Id] in table 'RecipientEventType'
ALTER TABLE [dbo].[RecipientEventType]
ADD CONSTRAINT [PK_RecipientEventType]
    PRIMARY KEY NONCLUSTERED ([Subscribers_Id], [Subscriptions_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Subscribers_Id] in table 'RecipientEventType'
ALTER TABLE [dbo].[RecipientEventType]
ADD CONSTRAINT [FK_RecipientEventType_Recipient]
    FOREIGN KEY ([Subscribers_Id])
    REFERENCES [dbo].[EntityBaseSet_Recipient]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Subscriptions_Id] in table 'RecipientEventType'
ALTER TABLE [dbo].[RecipientEventType]
ADD CONSTRAINT [FK_RecipientEventType_EventType]
    FOREIGN KEY ([Subscriptions_Id])
    REFERENCES [dbo].[EntityBaseSet_EventType]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RecipientEventType_EventType'
CREATE INDEX [IX_FK_RecipientEventType_EventType]
ON [dbo].[RecipientEventType]
    ([Subscriptions_Id]);
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_Recipient'
ALTER TABLE [dbo].[EntityBaseSet_Recipient]
ADD CONSTRAINT [FK_Recipient_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_EventType'
ALTER TABLE [dbo].[EntityBaseSet_EventType]
ADD CONSTRAINT [FK_EventType_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'EntityBaseSet_ImportanceLevel'
ALTER TABLE [dbo].[EntityBaseSet_ImportanceLevel]
ADD CONSTRAINT [FK_ImportanceLevel_inherits_EntityBase]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[EntityBaseSet]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------